package com.baidu.service.impl;

import com.baidu.dao.OrdersMapper;
import com.baidu.pojo.Order;
import com.baidu.pojo.Orders;
import com.baidu.pojo.Ticket;
import com.baidu.pojo.User;
import com.baidu.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public void addOrder(Order order) {
        ordersMapper.addOrder(order);
    }

    @Override
    public void updateUcount(User user) {
        ordersMapper.updateUcount(user);
    }

    @Override
    public void updateTNum(Ticket ticket) {
        ordersMapper.updateTNum(ticket);
    }

    @Override
    public List<Order> getAllOrderByUId(Integer uid) {
        return ordersMapper.getAllOrderByUId(uid);
    }

    @Override
    public void updateOrderState(Order order) {
        ordersMapper.updateOrderState(order);
    }


    //新增订单
    public void addOrders(Orders orders){
        ordersMapper.addOrders(orders);
    }

    //根据订单号查询订单信息
    public Orders getOrdersByOid(Integer oid){
        return ordersMapper.getOrdersByOid(oid);
    }

    //根据订单号修改订单信息
    public void updateOrdersByOid(Orders orders){
        ordersMapper.updateOrdersByOid(orders);
    }

    //根据订单号删除订单信息
    public void deleteOrdersById(Integer oid){
        ordersMapper.deleteOrdersById(oid);
    }

    //分页查询总记录数
    public int count(){
        int total=ordersMapper.count();
        return total;
    }

    //分页查询所有用户信息,以及关联的角色信息 第一个参数表示起始位置，第二个参数表示页面容量
    public List<Orders> getByPage(Integer currentPage,Integer pageSize){
        //计算起始位置
        int start=(currentPage-1)*pageSize;

        //执行分页查询
        List<Orders> list=ordersMapper.getByPage(start,pageSize);

        return list;
    }

    //    查询所有订单信息
    public List<Orders> getAllOrders(){
        return ordersMapper.getAllOrders();
    }

    //    根据指定tid查询订单信息
    public Orders getOrderByTid(Integer tid){
        return ordersMapper.getOrderByTid(tid);
    }

    @Override
    public Integer getAllOrderByUIdCount(Integer uid) {
        return ordersMapper.getAllOrderByUIdCount(uid);
    }

    @Override
    public List<Order> getAllOrderByUIdByPage(Integer currentPage,Integer pageSize,Integer uid) {
        return ordersMapper.getAllOrderByUIdByPage(currentPage,pageSize,uid);
    }
}
